package com.jh3502.vivo.function.me;

import android.support.annotation.NonNull;

import com.jh3502.vivo.base.BaseCallback;
import com.jh3502.vivo.base.BaseJson;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.base.BaseView;
import com.jh3502.vivo.utils.SpHelper;
import com.jh3502.vivo.utils.Utils;

import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class MePresenter extends BasePresenter<MePresenter.MeView> {
    MeModel mMeModel;

    MeView mMeView;


    public void setMeView(MeView mMeView) {
        this.mMeView = mMeView;
    }

    public void toUpdateUser(Map<String, Object> body) {
        mMeView.showLoadingDialog();
        if (mMeModel == null) {
            mMeModel = new MeModel(mMeView.getActContext());
        }

        mMeModel.updateUser(body, new BaseCallback(mMeView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                mMeView.updateUserSuccess();
            }
        });
    }

    public void getUser(Map<String, Object> body) {
        mMeView.showLoadingDialog();
        if (mMeModel == null) {
            mMeModel = new MeModel(mMeView.getActContext());
        }

        mMeModel.getUser(body, new BaseCallback(mMeView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                SpHelper.getInstance().saveUser(Utils.getInstance().jso2map(baseJson.getObj().toString()));
                mMeView.getUserSuccess();
            }
        });
    }


    @Override
    public void cancelCall() {

    }

    public interface MeView extends BaseView {
        void updateUserSuccess();

        void getUserSuccess();
    }
}
